package com.foreveross.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.service.BaseService;
import com.foreveross.util.JSONUtil;


public class BaseCostroller {

	@Resource
	private BaseService baseService;

	public Object findObject(Class clazz, String id) throws Exception {
		return baseService.findObject(clazz, id);
	}

	public String getWechatId(HttpServletRequest request) {
		return request.getParameter("wechatId");
	}

	/**
	 * 获取整形参数的值
	 * 
	 * @param request
	 * @param param
	 * @return
	 */
	public int getParametInt(HttpServletRequest request, String param) {
		String k = request.getParameter("param");
		int p = 0;
		try {
			if (k != null && !k.isEmpty()) {
				p = Integer.parseInt(k);
			}
		} catch (Exception e) {

		}
		return p;
	}

	/**
	 * 获取用户IP地址
	 * @param request
	 * @return
	 */
	public String getUserIP(HttpServletRequest request) {
		if (request.getHeader("x-forwarded-for") == null) {
			return request.getRemoteAddr();
		}
		return request.getHeader("x-forwarded-for");
	}


}
